Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System placement fix #7

Closed
wants to merge 3 commits into from
Closed

System placement fix #7

wants to merge 3 commits into from

Conversation

nfreader
Copy link
Owner

Makes system placement for newly generated automatic systems better.
#5

@nfreader
Copy link
Owner Author

Current status:
Systems only go into quadrants: (X,-Y)
I may be terrible at math. Hm.

0 0
10 -10
8 -10
8 -15
12 -13
15 -11
11 -15
11 -18
15 -10
3 1
4 -1
5 -6
2 -10

Code is:

<?php
$placementfactor = floor(rand(1,4));
    if ($placementfactor === 4) { //+,+
      $newX = $host->coord_x + floor(rand(-5,5));
      $newY = $host->coord_y + floor(rand(-5,5));
    } elseif ($placementfactor === 3)  { //-,-
      $newX = $host->coord_x - floor(rand(-5,5));
      $newY = $host->coord_y - floor(rand(-5,5));
    } elseif ($placementfactor === 2) { //+,-
      $newX = $host->coord_x + floor(rand(-5,5));
      $newY = $host->coord_y - floor(rand(-5,5));      
    } else { //-,+
      $newX = $host->coord_x - floor(rand(-5,5));
      $newY = $host->coord_y + floor(rand(-5,5));      
    }

@adam000
Copy link

adam000 commented Aug 17, 2014

  • For your examples, what were the values of $host->coord_x and $host->coord_y? If they were sufficiently positive x and negative y, that would be why you are getting these 3rd quadrant values.
  • (3, 1) is not in the third quadrant, which is what makes me suspect this
  • When I ran this on my computer, with debug output, $placementFactor was consistently 0. I don't know why, but this would give you "only positive" values. I'm not sure what $placementFactor is supposed to do, though. rand() is already giving you positive and negative values. You don't need the +/- jazz.
  • php.net recommends mt_rand() for being faster and more random.
  • rand() returns an int, so there's no need to floor() it
  • If you really need $placementFactor, might I recommend making the placement rands be from 0 to 5?

@adam000
Copy link

adam000 commented Aug 17, 2014

I realized I need a more robust map editor, so this is the first step
towards making that a reality. First up, a tool to link systems just by
clicking on them. In theory…
@nfreader
Copy link
Owner Author

@adam000 Thank you, that helps tremendously!

@nfreader nfreader closed this Oct 1, 2014
@nfreader
Copy link
Owner Author

nfreader commented Oct 1, 2014

49 commits behind? That's mayhem.

@nfreader nfreader deleted the system-placement-fix branch October 1, 2014 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants